package top.laoshuzi.cloudplatform.network;


import java.net.InetSocketAddress;

/**
 * Created by mouse on 2017/12/28.
 */

public class NetworkService {

    private static final int SERVER_PORT = 12345;

    private SimpleServer server;
    private Thread serverThread;

    private NetworkService() {
        server = new SimpleServer();
    }

    public static NetworkService getInstance() {
        return InstanceHolder.INSTANCE;
    }

    private static class InstanceHolder {
        private static NetworkService INSTANCE = new NetworkService();
    }

    public void start(final int port) {
        serverThread = new Thread(new Runnable() {
            @Override
            public void run() {
                server.bind(new InetSocketAddress(port));
            }
        });
        serverThread.start();
    }

    public void stop() {
        server.shutdown();
    }

}
